#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

int main()
{
    int m, n;
    cin >> m >> n;
    if (m == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    string s;
    string table = "0123456789ABCDEF";

    bool flag = false;
    if (m < 0)
    {
        m = -m;
        flag = true;
    }
    while (m)
    {
        s += table[m % n];
        m /= n;
    }

    if (flag == true)
    {
        s += "-";
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}